/************************************************************
 * M3D_RECT.CPP                                    14.11.2006
 *
 * .
 ************************************************************/

#include "stdafx.h"
//#include "ap_comm.h"
#include "m3d\m3d.h"
#include "m3d\m3d_rect.h"

//
// class m3dRECT
//

/***************************************************************
* m3dRECT::SetPosInside()
*
***************************************************************/
void m3dRECT::SetPosInside(const m3dRECT &absRect, const m3dRECT &ofsRect)
{
   l = ofsRect.l + (ofsRect.l >= 0.f ? absRect.l : absRect.r);
   r = ofsRect.r + (ofsRect.r >= 0.f ? l : absRect.r);
   t = ofsRect.t + (ofsRect.t >= 0.f ? absRect.t : absRect.b);
   b = ofsRect.b + (ofsRect.b >= 0.f ? t : absRect.b);
   return;
}

/***************************************************************
* m3dRECT::IsIntersect()
*
***************************************************************/
BOOL m3dRECT::IsIntersect(const m3dRECT &a) const
{
   if (r <= a.l || l >= a.r) {
      return FALSE;
   }
   if (b <= a.t || t >= a.b) {
      return FALSE;
   }
   return TRUE;
}

/***************************************************************
* m3dRECT::Extend()
*
***************************************************************/
void m3dRECT::Extend(const m3dRECT &r)
{
   if (IsEmpty()) {
      *this = r;
   } else {
      Extend(r.l, r.t);
      Extend(r.r - M3D_EPSILON * 100.0f, r.t);
      Extend(r.l, r.b - M3D_EPSILON * 100.0f);
      Extend(r.r - M3D_EPSILON * 100.0f, r.b - M3D_EPSILON * 100.0f);
   }
   return;
}

/***************************************************************
* m3dRECT::Extend()
*
***************************************************************/
void m3dRECT::Extend(float x, float y)
{
   if (IsEmpty()) {
      l = x; 
      t = y;
      r = x + M3D_EPSILON * 100.0f;
      b = y + M3D_EPSILON * 100.0f;
   } else {
	  l = m3dFMin(l, x);
	  t = m3dFMin(t, y);
	  r = m3dFMax(r, x + M3D_EPSILON * 100.0f);
	  b = m3dFMax(b, y + M3D_EPSILON * 100.0f);
   }
   return;
}

//
// End-of-file M3D_RECT.CPP
//
